package org.example.springbirthday.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.ResultSetType;
import org.example.springbirthday.model.UserInfo;

import java.io.InputStream;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/7
 * Time: 02:05
 */
@Mapper
public interface UserInfoMapper {
     @Select("select * from user_info where user_name = #{userName}")
     UserInfo getUserByName(String userName);

     @Select("select * from user_info where id = #{id}")
     UserInfo getUserById(Integer id);

     @Insert("insert into user_info (user_name,password,birthday,power_status,create_time_status,update_time_status,file) values (#{userName},#{password},#{birthday},#{powerStatus},#{createTimeStatus},#{updateTimeStatus},#{file})")
     Integer register(UserInfo userInfo);

     @Select(("select * from user_info"))
     List<UserInfo> getUserInfoList();

     @Select("select * from user_info limit #{size} offset #{offset}")
     List<UserInfo> getUserInfoListByPageAndSize(Integer offset,Integer size);

     @Delete("delete from user_info where id = #{id}")
     Integer cancel(Integer id);

     @Update("update user_info set bless_count = #{blessCount} where id = #{id}")
     Integer updateBlessCount(UserInfo userInfo);

     @Update("update user_info set user_name = #{userName},password = #{password},birthday = #{birthday},update_time = now(),update_time_status = #{updateTimeStatus} where id = #{id}")
     Integer update(UserInfo userInfo);

     @Update("update user_info set file = #{file} where id = #{id}")
     Integer save(UserInfo userInfo);

     @Select("select file from user_info where id = #{id}")
     @Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize = 1000)
     @ResultType(java.io.InputStream.class)
     InputStream getFileById(Integer id);
}
